package org.kzwl.book.controller.filter;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

/**
 * @ClassName asd
 * @Description
 * @Author JiaHeng.Guo
 * @Date 2019/7/24 10:06
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    ArrayList<String> excludes = new ArrayList<String>() {{
//        add("/swagger-resources");
//        add("/webjars/**");
//        add("/doc.html");
//        add("/error");
//        add("/user/**");
//        add("/v2/api-docs-ext");
        add("/**");
    }};
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**").excludePathPatterns(excludes);    // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
    }
    @Bean
    public JWTHandlerInterceptor authenticationInterceptor() {
        return new JWTHandlerInterceptor();
    }
}
